package org.springextensions.actionscript.ioc.factory.xml.parser.support.referenceresolvers
{
	import org.springextensions.actionscript.ioc.factory.IObjectFactory;
	import org.springextensions.actionscript.ioc.factory.config.IResourceReference;
	import org.springextensions.actionscript.ioc.factory.support.AbstractReferenceResolver;
	import org.springextensions.actionscript.mvcs.service.operation.IOperation;
	import org.springextensions.actionscript.utils.Assert;

	public class ResourceReferenceResolver extends AbstractReferenceResolver
	{
		public function ResourceReferenceResolver(factory:IObjectFactory)
		{
			super(factory);
		}
		
		/**
	     * @inheritDoc
	     *
	     * @throws flash.errors.IllegalOperationError  This method should be implemented by a subclass
	     */
	    override public function canResolve(property:Object):Boolean {
	      return (property is IResourceReference);
	    }
	
	    /**
	     * @inheritDoc
	     *
	     * @throws flash.errors.IllegalOperationError  This method should be implemented by a subclass
	     */
	    override public function resolve(property:Object):Object {
	    	Assert.instanceOf(property, IResourceReference, "ResourceReferenceResolver.resolve() expects a IResourceReference value");
	    	var resourceName:String = IResourceReference(property).resourceName;
	    	var resource:IOperation = factory.getObject(resourceName);

	      return resource.result;
	    }
	}
}